﻿using System;
using System.Collections.Generic;
using System.Text;

namespace GenericCommTool
{
    public static class ObjectExtensions
    {
        private static readonly string ClassName = "@ClassName";
        private static readonly string ClassDesc = "@ClassDesc";
        private static readonly string ProjectName = "@ProjectName";

        /// <summary>
        /// 替换
        /// </summary>
        /// <param name="source"></param>
        /// <param name="str"></param>
        /// <param name="repStr"></param>
        /// <returns></returns>
        public static string ReplaceTemp(this string source, string className, string classDesc, string @namespace)
        {
            return source.Replace(ProjectName, @namespace)
                .Replace(ClassName, className)
                .Replace(ClassDesc, classDesc);
        }

        public static bool IsNullOrEmpty(this string str)
        {
            return string.IsNullOrEmpty(str) || str.Trim().Length == 0;
        }

        public static bool IgnoreEquals(this string str, string target)
        {
            return string.Equals(str, target, StringComparison.OrdinalIgnoreCase);
        }

        public static bool IsQuit(this string str)
        {
            return !(str.IgnoreEquals("y") || str.IgnoreEquals("yes"));
            //return str.IgnoreEquals("q")
            //       || str.IgnoreEquals("e")
            //        || str.IgnoreEquals("quit")
            //       || str.IgnoreEquals("exit");
        }
    }
}
